package com.treeroot.addservice.address.service.impl;

import com.treeroot.addservice.address.entity.PcAdCity;
import com.treeroot.addservice.address.entity.PcAdProvince;
import com.treeroot.addservice.address.entity.PcAdTown;
import com.treeroot.addservice.address.mapper.PcAdProvinceMapper;
import com.treeroot.addservice.address.service.PcAdProvinceService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 省份信息表 服务实现类
 * </p>
 *
 * @author TreeRoot
 * @since 2022-05-13
 */
@Service
@Transactional
public class PcAdProvinceServiceImpl extends ServiceImpl<PcAdProvinceMapper, PcAdProvince> implements PcAdProvinceService {

    //   根据 省id 拿到 省String Code


    //    然后 把 省的code 给到要拿去做对比的provinceCode身上
    @Override
    public List<PcAdCity> getCity(String provinceCode) {

        List<PcAdCity> city = baseMapper.getCity(provinceCode);
        return city;
    }

    @Override
    public List<PcAdTown> getTown(String cityCode) {
        List<PcAdTown> town = baseMapper.getTown(cityCode);
        return town;
    }
    /**
     * 查出子分类，组装起来
     * @param provinceCode  省份code
     * @param cityCode      市code
     */
    @Override
    public Map getAddress(String provinceCode, String cityCode) {
        //首先展示出所有省
        PcAdProvince provinces  = baseMapper.selectById(null);
        //通过省 code查市
        List<PcAdCity> city = baseMapper.getCity(provinceCode);
        //通过市code查镇
        List<PcAdTown> town = baseMapper.getTown(cityCode);
        Map map =new HashMap<>();
        map.put("province", provinces);
        map.put("city", city);
        map.put("town", town);
        return map;
    }


}
